package com.cxf.cxfdaybat.job.validator;

import com.cxf.cxfdaybat.entity.Person;
import org.springframework.batch.item.validator.ValidationException;
import org.springframework.batch.item.validator.Validator;
import javax.validation.ConstraintViolation;
import java.util.Set;

/**
 * description: PersonValidator <br>
 * date: 2021/11/12 19:17 <br>
 * author: cxf <br>
 * version: 1.0 <br>
 */
public class PersonValidator implements Validator<Person> {

    private javax.validation.Validator validator;

    @Override
    public void validate(Person person) throws ValidationException {
        Set<ConstraintViolation<Person>> validate = validator.validate(person);

        if (validate.size() > 0) {
            StringBuilder message = new StringBuilder();
            for (ConstraintViolation<Person> constraintViolation: validate) {
                message.append(constraintViolation.getMessage() + "\n");
            }
            throw new ValidationException(message.toString());
        }
    }




}
